package com.yuncheng.spcyApi.webOffice;

import com.yuncheng.annotation.AutoLog;
import com.yuncheng.spcyApi.busService.SpcyDaService;
import com.yuncheng.spcyApi.entity.SpcyDaWjjl;
import com.yuncheng.spcyApi.entity.SpcyZltxwjFlow;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "档案管理-WebOffice在线文档编辑接口")
@RestController
@RequestMapping("/api/spzx-spcy/daWebOfficeApi")
public class DaWebOfficeApi {

    @Resource
    private WebOfficeFile webOfficeFIle;

    @Resource
    private SpcyDaService spcyDaService;

    @AutoLog(value = "查看模式-服务端-打开在线文档")
    @ApiOperation(value = "查看模式-服务端-打开在线文档")
    @ApiImplicitParam(name = "id",value = "档案id")
    @GetMapping(value = "onlineSeeOpenFile")
    public HttpResult<?> onlineSeeOpenFile(@RequestParam(value = "id",defaultValue = "") String id){
        SpcyDaWjjl wjjl = spcyDaService.getDaFileByDaId(id);
        if (wjjl == null){
            return HttpResult.error("文件不存在");
        }
        if (StringUtils.isBlank(wjjl.getFwjlj())){
            return HttpResult.error("文件不存在！");
        }
        if (StringUtils.isNotBlank(wjjl.getFwjlx()) && wjjl.getFwjlx().equals(".pdf")){
            return HttpResult.error("当前文档为pdf文档，请选择重新编辑文档");
        }

        String url = webOfficeFIle.openSeeFileByDa(wjjl,wjjl.getId(),wjjl.getFwjlj(),1);
        Map resultMap = new HashMap();
        resultMap.put("wordUrl",url);
        return HttpResult.ok(resultMap);
    }


}
